@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <div class="content">
        <div class="header">

            <h1 class="page-title">后台管理</h1>
            <ul class="breadcrumb">
                <li>活跃管理</li>
                <li class="active">列表</li>
                <!-- <li class="active">标签列表</li> -->
            </ul>

        </div>
        <div class="main-content">
            <div class="btn-toolbar list-toolbar">
                <form class="form-inline" action="" method="get">
                    <!--  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" ><i class="fa fa-plus"></i> 标签</button> -->
                    <div class="form-group">
                        <input type="text" value="{{$id}}" class="form-control" name="id" placeholder="用户编号">
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control"  value="{{$name}}"   name="name" placeholder="用户昵称">
                    </div>
                    <div class="form-group">
                        <input type="text" value="{{$mobile}}"  class="form-control" name="mobile" placeholder="用户手机号">
                    </div>
                    <button type="submit" class="btn btn-default">筛选</button>
                </form>
            </div>

            <div class="row">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">标签列表<!-- <span class="label label-warning">+10</span> --></div>
                        <table class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th width="5%">编号</th>
                                <th width="5%">用户名</th>
                                <th width="5%">手机号</th>
                                <th width="5%">一级用户个数</th>
                                <th width="10%">二级用户个数</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($userActives as $active)
                                <?php
                                    $user = $active->user;

                                    if(!$user){
                                        continue;
                                    }else{

                                    }
                                    $activeOneSum = $active->getOneNumber($active->userid);
                                    $activeUsers = $active->getUser($active->userid);
                                        $total = 0;
                                    foreach($activeUsers as $acUser){
                                        $total += $acUser->getTwoNumber($acUser->friend);
                                    }
                                ?>
                                <tr>
                                    <td>{{$user->id}}</td>
                                    <td>{{$user->name?$user->name:$user->nickname}}</td>
                                    <td>{{$user->mobile}}</td>
                                    <td>{{$activeOneSum}}</td>
                                    <td>{{$total}}</td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    {{$userActives->appends(['mobile'=>$mobile,'name'=>$name,'id'=>$id])->render()}}
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            //提交信息
            $(".user_status").click(function(){
                var id     = $(this).attr("data-id");        //被操作的记录id
                var status = $(this).attr("data-status");    //被修改的状态
                var classid= "user_status"+id;
                var text   = status==1 ? '解封' : "封禁";    //修改后的操作文字
                var statust= status==1 ? '已封禁' : "正常";  //修改后的状态文字
                var css    = status==1 ? 'label label-danger' : "label label-success";   //修改后css样式
                var newstatus = status==1 ? 0 : 1;           //修改后更新的状态

                $.ajax({
                    type:"get",
                    url:"/user/upstatus",
                    data:{id:id, status:status},
                    dataType:'json',
                    success:function(result){
                        if(result.code==1){
                            $("#"+classid).html(text);
                            $("#"+classid).attr('data-status', newstatus);
                            $("#"+classid).parent().prev().children().attr("class", css).text(statust);
                        }else{
                            alert(result.msg);
                        }
                    }
                });
            });
        })
    </script>
@endsection